/**
 * Copyright(C) 2008 Matthias Braunhofer
 * All rights reserved
 *
 * Created on: 03.09.2008
 */

package it.cums.model;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;

public class OrderedProducts {
	private ArrayList<OrderedProduct> orderedProducts = new ArrayList<OrderedProduct>();
	private ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();

	public ArrayList<OrderedProduct> getOrderedProducts() {
		return orderedProducts;
	}
	
	public void addOrderedProduct(OrderedProduct p) {
		orderedProducts.add(p);
		p.setPropertyChangeListeners(listeners);
		notifyListeners();
	}
	
	public void removeOrderedProduct(OrderedProduct p) {
		orderedProducts.remove(p);
		notifyListeners();
	}
	
	public OrderedProducts() {
		orderedProducts = new ArrayList<OrderedProduct>();
	}
	
	private void notifyListeners() {
		for (PropertyChangeListener listener : listeners) {
			listener.propertyChange(null);
		}
	}
	
	public void addChangeListener(PropertyChangeListener listener) {
		listeners.add(listener);
	}
	
	public void removeChangeListener(PropertyChangeListener listener) {
		listeners.remove(listener);
	}
}
